package com.hc.sss.service.impl;

import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import com.hc.sss.common.ResultMap;
import com.hc.sss.mapper.AddressMapper;
import com.hc.sss.pojo.Address;
import com.hc.sss.service.AddressService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

import javax.annotation.Resource;

@Service
public class AddressServiceImpl implements AddressService {

    @Resource
    private AddressMapper addressMapper;

    @Override
    public int insertAddress(Address address) {
        return addressMapper.insertAddress(address);
    }

	@Override
	public ResultMap<Address> findListAddress(Map<String, Object> param) {
		   Integer pageNo = Integer.valueOf(1);
		    int PageSize = 5;
		    if (param.get("page") != null && !"".equals(param.get("page")))
		      pageNo = Integer.valueOf(param.get("page").toString()); 
		    if (param.get("limit") != null && !"".equals(param.get("limit")))
		      PageSize = Integer.valueOf(param.get("limit").toString()).intValue(); 
		    List<Address> list =addressMapper.findListAddress(param);
		    PageHelper.startPage(pageNo.intValue(), PageSize);
		    PageInfo<Address> info = new PageInfo(list);
		    return new ResultMap(list, (int)info.getTotal());
	}

	@Override
	public int deleteByPrimaryKey(String addrId) {
		// TODO Auto-generated method stub
		return addressMapper.deleteByPrimaryKey(addrId);
	}

	@Override
	public Address selectByPrimaryKey(String addrId) {
		// TODO Auto-generated method stub
		return addressMapper.selectByPrimaryKey(addrId);
	}

	@Override
	public int updateByPrimaryKeySelective(Address record) {
		// TODO Auto-generated method stub
		return addressMapper.updateByPrimaryKeySelective(record);
	}

	@Override
	public int addAddres(Address address) {
		// TODO Auto-generated method stub
		return addressMapper.addAddres(address);
	}
}
